﻿Imports lbGlobalcom
Public Class fConsignaciones
    Dim daConsigna As dsCajaTableAdapters.CAJ_CONSIGNATableAdapter
    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
        Try
            CAJ_CONSIGNABindingSource.AddNew()
            Dim Consec As Integer = daConsigna.GetConsec()
            IDCONSIGNATextBox.Text = Consec
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub fConsignaciones_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daConsigna = New dsCajaTableAdapters.CAJ_CONSIGNATableAdapter
            DsCaja.CAJ_CONSIGNA.Columns("FECHA").DefaultValue = Date.Today
            DsCaja.CAJ_CONSIGNA.Columns("IDCAJA").DefaultValue = CustomPrincipal.IdCaja
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnBuscaBanco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaBanco.Click
        Try
            Dim fListBco As New fListaBancos
            If fListBco.ShowDialog = Windows.Forms.DialogResult.OK Then
                IDBANCOTextBox.Text = fListBco.idBco
                IDBANCOTextBox.Focus()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub IDBANCOTextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles IDBANCOTextBox.Validated
        Try
            If IDBANCOTextBox.Text.Trim.Length > 0 Then
                Dim cBco As New cBanco(IDBANCOTextBox.Text)
                lbDescripBanco.Text = cBco.Descripcion
            Else
                lbDescripBanco.Text = ""
            End If
        Catch ex As Exception
            lbDescripBanco.Text = ""
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                CAJ_CONSIGNABindingSource.RemoveCurrent()
                Salvar(False)
            End If
        Catch ex As Exception

        End Try
    End Sub
    Private Sub Salvar(ByVal msj As Boolean)
        Try
            Validate()
            CAJ_CONSIGNABindingSource.EndEdit()
            daConsigna.Update(DsCaja.CAJ_CONSIGNA)
            If msj Then _
                MessageBox.Show("Se salvo registro con exito", "Salvar Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub CAJ_CONSIGNABindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAJ_CONSIGNABindingNavigatorSaveItem.Click
        Salvar(True)
    End Sub

    
End Class